From d8b6dbd888de8908ffa81d73e00f74ba3143ef66 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 2 Jan 2016 14:59:56 -0800 Subject: [PATCH] menubar: prefer early return --- gtk/gtkmenubar.c | 181 ++++++++++++++++++++++++----------------------- 1 file changed, 91 insertions(+), 90 deletions(-) diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c index b26ffe437d..ef117eb0eb 100644 --- a/gtk/gtkmenubar.c +++ b/gtk/gtkmenubar.c @@ -512,124 +512,125 @@ gtk_menu_bar_allocate (GtkCssGadget *gadget, menu_shell = GTK_MENU_SHELL (widget); priv = menu_bar->priv; - if (menu_shell->priv->children) - { - remaining_space = *allocation; - requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize)); + if (!menu_shell->priv->children) + return; - if (priv->pack_direction == GTK_PACK_DIRECTION_LTR || - priv->pack_direction == GTK_PACK_DIRECTION_RTL) - { - int size = remaining_space.width; - gboolean ltr = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (priv->pack_direction == GTK_PACK_DIRECTION_LTR); + remaining_space = *allocation; + requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize)); - for (children = menu_shell->priv->children; children; children = children->next) - { - GtkRequestedSize request; - child = children->data; + if (priv->pack_direction == GTK_PACK_DIRECTION_LTR || + priv->pack_direction == GTK_PACK_DIRECTION_RTL) + { + int size = remaining_space.width; + gboolean ltr = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (priv->pack_direction == GTK_PACK_DIRECTION_LTR); - if (!gtk_widget_get_visible (child)) - continue; + for (children = menu_shell->priv->children; children; children = children->next) + { + GtkRequestedSize request; + child = children->data; - request.data = child; - gtk_widget_get_preferred_width_for_height (child, - remaining_space.height, - &request.minimum_size, - &request.natural_size); - gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child), - &toggle_size); - request.minimum_size += toggle_size; - request.natural_size += toggle_size; + if (!gtk_widget_get_visible (child)) + continue; - gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size); + request.data = child; + gtk_widget_get_preferred_width_for_height (child, + remaining_space.height, + &request.minimum_size, + &request.natural_size); + gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child), + &toggle_size); + request.minimum_size += toggle_size; + request.natural_size += toggle_size; - g_array_append_val (requested_sizes, request); + gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size); - size -= request.minimum_size; - } + g_array_append_val (requested_sizes, request); - size = gtk_distribute_natural_allocation (size, - requested_sizes->len, - (GtkRequestedSize *) requested_sizes->data); + size -= request.minimum_size; + } - for (i = 0; i < requested_sizes->len; i++) - { - GtkAllocation child_allocation = remaining_space; - GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i); + size = gtk_distribute_natural_allocation (size, + requested_sizes->len, + (GtkRequestedSize *) requested_sizes->data); - child_allocation.width = request->minimum_size; - remaining_space.width -= request->minimum_size; + for (i = 0; i < requested_sizes->len; i++) + { + GtkAllocation child_allocation = remaining_space; + GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i); - if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) && - GTK_MENU_ITEM (request->data)->priv->right_justify) - ltr = !ltr; + child_allocation.width = request->minimum_size; + remaining_space.width -= request->minimum_size; - if (ltr) - remaining_space.x += request->minimum_size; - else - child_allocation.x += remaining_space.width; + if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) && + GTK_MENU_ITEM (request->data)->priv->right_justify) + ltr = !ltr; - gtk_widget_size_allocate (request->data, &child_allocation); - } - } - else - { - int size = remaining_space.height; - gboolean ttb = (priv->pack_direction == GTK_PACK_DIRECTION_TTB); + if (ltr) + remaining_space.x += request->minimum_size; + else + child_allocation.x += remaining_space.width; - for (children = menu_shell->priv->children; children; children = children->next) - { - GtkRequestedSize request; - child = children->data; + gtk_widget_size_allocate (request->data, &child_allocation); + } + } + else + { + int size = remaining_space.height; + gboolean ttb = (priv->pack_direction == GTK_PACK_DIRECTION_TTB); - if (!gtk_widget_get_visible (child)) - continue; + for (children = menu_shell->priv->children; children; children = children->next) + { + GtkRequestedSize request; + child = children->data; - request.data = child; - gtk_widget_get_preferred_height_for_width (child, - remaining_space.width, - &request.minimum_size, - &request.natural_size); - gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child), - &toggle_size); - request.minimum_size += toggle_size; - request.natural_size += toggle_size; + if (!gtk_widget_get_visible (child)) + continue; - gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size); + request.data = child; + gtk_widget_get_preferred_height_for_width (child, + remaining_space.width, + &request.minimum_size, + &request.natural_size); + gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child), + &toggle_size); + request.minimum_size += toggle_size; + request.natural_size += toggle_size; - g_array_append_val (requested_sizes, request); + gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size); - size -= request.minimum_size; - } + g_array_append_val (requested_sizes, request); - size = gtk_distribute_natural_allocation (size, - requested_sizes->len, - (GtkRequestedSize *) requested_sizes->data); + size -= request.minimum_size; + } - for (i = 0; i < requested_sizes->len; i++) - { - GtkAllocation child_allocation = remaining_space; - GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i); + size = gtk_distribute_natural_allocation (size, + requested_sizes->len, + (GtkRequestedSize *) requested_sizes->data); - child_allocation.height = request->minimum_size; - remaining_space.height -= request->minimum_size; + for (i = 0; i < requested_sizes->len; i++) + { + GtkAllocation child_allocation = remaining_space; + GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i); - if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) && - GTK_MENU_ITEM (request->data)->priv->right_justify) - ttb = !ttb; + child_allocation.height = request->minimum_size; + remaining_space.height -= request->minimum_size; - if (ttb) - remaining_space.y += request->minimum_size; - else - child_allocation.y += remaining_space.height; + if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) && + GTK_MENU_ITEM (request->data)->priv->right_justify) + ttb = !ttb; - gtk_widget_size_allocate (request->data, &child_allocation); - } - } + if (ttb) + remaining_space.y += request->minimum_size; + else + child_allocation.y += remaining_space.height; - g_array_free (requested_sizes, TRUE); + gtk_widget_size_allocate (request->data, &child_allocation); + } } + + g_array_free (requested_sizes, TRUE); } + static void gtk_menu_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -- 2.30.2